class Solution:
    def __init__(self):
        self.result = []
        self.path = []
    
    def backtracking(self, nums, start_index):
        self.result.append(self.path[:])  # 收集子集，要放在终止添加的上面，否则会漏掉自己
        if start_index >= len(nums):  # 终止条件可以不加
            return
        
        for i in range(start_index, len(nums)):
            self.path.append(nums[i])
            self.backtracking(nums, i + 1)
            self.path.pop()
    
    def subsets(self, nums):
        self.result = []
        self.path = []
        self.backtracking(nums, 0)
        return self.result